import 'package:flutter/material.dart';

import '../../../constants/enums/device_status.dart';

/// 设备状态标签 Widget
class DeviceStatusBadge extends StatelessWidget {
  final DeviceStatus status;

  const DeviceStatusBadge({Key? key, required this.status}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final color = _getStatusColor(status);
    final text = status.displayName;

    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 6.0, vertical: 2.0),
      decoration: BoxDecoration(
        color: color.withOpacity(0.15),
        borderRadius: BorderRadius.circular(4.0),
      ),
      child: Text(
        text,
        style: TextStyle(
          color: color,
          fontSize: 10,
          fontWeight: FontWeight.w600,
        ),
      ),
    );
  }

  /// 根据设备状态获取颜色
  Color _getStatusColor(DeviceStatus status) {
    switch (status) {
      case DeviceStatus.online:
        return Colors.green;
      case DeviceStatus.offline:
        return Colors.grey;
      case DeviceStatus.fault:
        return Colors.red;
      case DeviceStatus.disabled:
        return Colors.blueGrey;
      case DeviceStatus.maintenance:
        return Colors.orange;
      case DeviceStatus.sleep:
         return Colors.blue;
      case DeviceStatus.inactive:
         return Colors.purple;
      case DeviceStatus.unknown:
      default:
        return Colors.black54;
    }
  }
} 